package com.mrobuy.jd.category;

import com.gavel.database.SQLExecutor;
import com.jd.open.api.sdk.JdClient;
import com.mrobuy.jd.JdClientFactory;
import com.mrobuy.jd.api.Jos;
import com.mrobuy.jdvc.entity.VCCategory;
import com.mrobuy.jdvc.entity.VCCategorySaleProp;
import com.mrobuy.util.IdentifierGen;

import java.util.List;

public class VCCategorySalePropsLoader {

    public static void main(String[] args) throws Exception {


        List<VCCategory> vcCategories = SQLExecutor.executeQueryBeanList("select * from VC_CATEGORY where LEVEL = 3", VCCategory.class);

        for (VCCategory vcCategory : vcCategories) {
            System.out.println(vcCategory);
            load(vcCategory.getId(), JdClientFactory.jdClient());
        }

    }

    public static void load(int cid,  JdClient client) throws Exception {

        SQLExecutor.execute("delete from VC_CATEGORY_SALE_PROP where CID = ?", cid);


        List<VCCategorySaleProp> saleProps = Jos.salePropFindClient(client)
                .setCid3(cid)
                .call();

        for (VCCategorySaleProp saleProp : saleProps) {
            saleProp.setId(IdentifierGen.uuid());
            SQLExecutor.insert(saleProp);
        }

    }

}
